package com.example.flow.dao.impl;

import com.example.flow.dao.FlowApproveApplyDao;
import com.example.flow.dao.mapper.FlowApproveApplyMapper;
import com.example.flow.dao.model.FlowApproveApply;
import com.example.flow.dao.model.example.FlowApproveApplyExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @author safe
 * @date 2021/1/31
 */
@Service
public class FlowApproveApplyDaoImpl implements FlowApproveApplyDao {
    @Autowired
    private FlowApproveApplyMapper flowApproveApplyMapper;

    @Override
    public FlowApproveApply queryOne(String applyId, String orderId) {
        FlowApproveApply query = new FlowApproveApply();
        query.setApplyId(applyId);
        query.setOrderId(orderId);
        return flowApproveApplyMapper.selectOne(query);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveFlowApproveApply(FlowApproveApply flowApproveApply) {
        return flowApproveApplyMapper.insert(flowApproveApply) == 1;
    }

    @Override
    public boolean updateByExample(FlowApproveApply record) {
        FlowApproveApplyExample updateExample = new FlowApproveApplyExample();
        updateExample.createCriteria()
                .andApplyIdEqualTo(record.getApplyId());
        record.setUpdateTime(new Date());
        return flowApproveApplyMapper.updateByExample(record, updateExample) == 1;
    }

    @Override
    public boolean updateByExampleBySelective(FlowApproveApply record) {
        FlowApproveApplyExample updateExample = new FlowApproveApplyExample();
        updateExample.createCriteria()
                .andApplyIdEqualTo(record.getApplyId());
        record.setUpdateTime(new Date());
        return flowApproveApplyMapper.updateByExampleSelective(record, updateExample) == 1;
    }
}
